package app

import (
	"github.com/kataras/iris/context"
	"github.com/kataras/iris"

	"github.com/kataras/iris/core/router"
	"app/service"
	"app/controller/host"
	"app/controller/task"
)
//开始模块
func Start(app *iris.Application)  {
	updateIf()
	registModule()
	registRounter(app)
	registTask()
}
//注册模型
func registModule()  {
	//db.Engine.Sync2(new(model.User))
	//db.Engine.Sync2(new(model.Article))
}
type Visitor struct {
	Username string
	Mail     string
}
//注册路由
func registRounter(app *iris.Application)  {
	base:="/Users/hellopyj/Src/Go/egg_go/src/static"
	app.StaticWeb("game", base+"/web")
	app.Any("test",func(ctx context.Context ) {
		ctx.WriteString("sss")

	})
	//用户
	app.PartyFunc("/user", func(user router.Party) {


	})
	//主机
	app.PartyFunc("/host", func(hosts router.Party) {
		hosts.Post("/list",host.List)
		hosts.Post("/store",host.Store)
		hosts.Any("/del/{id:int min(1)}",host.Del)
		hosts.Any("/ping/{id:int min(1)}",host.Ping)
	})
	//任务
	app.PartyFunc("/task", func(tasks router.Party) {
		tasks.Post("/list",task.List)
		tasks.Post("/run/{id:int min(1)}",task.Run)
		tasks.Post("/store",task.Store)
		tasks.Any("/del/{id:int min(1)}",task.Del)
		tasks.Any("/status/{id:int min(1)}/{status:int}",task.Status)
	})
	tmpl := iris.HTML(base+"/app", ".html")
	tmpl.Reload(true)
	app.RegisterView(tmpl)

}
//注册任务
func registTask()  {
	serviceTask := new(service.Task)
	serviceTask.Initialize()
}
////载入缓存
//func getCache()  {
//	cache.ReloadAll()
//}
func updateIf()  {

}